/**
 * @param {string} s
 * @return {number}
 */
var lengthOfLongestSubstring = function (s) {
  let str = "";
  let arr = [];
  for (let i = 0; i < s.length; i++) {
    let index = str.indexOf(s[i]);
    if (index != -1) {
      // 包含
      arr.push(str);
      if (index == str.length - 1) {
        // 和前一个字符相同
        // arr.push(str);
        str = s[i];
      } else {
        // arr.push(str);
        str = str.substring(index + 1);
        str += s[i];
      }
    } else {
      // 不包含
      str += s[i];
    }
  }
  arr.push(str);

  let newArr = arr.sort((a, b) => b.length - a.length);
  console.log(newArr);
  console.log(newArr[0].length);
};
var s = "pwwkewwwhhygyfhuujw";
let result = lengthOfLongestSubstring(s);
console.log(result);
